package com.choosefine.it.team.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.team.model.TeamTypeInfo;
import com.choosefine.it.team.service.TeamTypeInfoService;
import com.github.pagehelper.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/teamTypeInfo")
@Api(value = "控制台——班组类别信息分页", description = "毛俊")
public class TeamTypeInfoController extends BaseController {

	@Autowired
	TeamTypeInfoService teamTypeInfoService;

	@ApiOperation(value = "获得班组类别list集合分页", notes = "", response = TeamTypeInfo.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value = "起始页", required = true, dataType = "Integer", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示的行数", required = true, dataType = "Integer", paramType = "query") })
	@RequestMapping(value = "/getTeamTypeInfoList", method = RequestMethod.GET)
	public String getTeamTypeList(@RequestParam Integer pageNum,
			@RequestParam Integer pageSize) {
		String result = null;
		PageDTO page = new PageDTO();
		page.setPageNum(pageNum);
		page.setPageSize(pageSize);
		Page<TeamTypeInfo> list = teamTypeInfoService.getAllTeamInfoType(page);
		if (list != null) {
			result = responseArraySuccess(list.toPageInfo());
		} else {
			result = responseFail(ResultCode.MSG_ERROR);
		}
		return result;
	}

	@ApiOperation(value = "根据id查找班组类别信息", notes = "", response = TeamTypeInfo.class)
	@ApiImplicitParam(name = "id", value = "班组类别ID", required = true, dataType = "Integer", paramType = "path")
	@RequestMapping(value = "/getTeamTypeInfoById/{id}", method = RequestMethod.GET)
	public String getTeamTypeInfoById(@PathVariable Integer id) {
		String result = null;
		if (id >= 0) {
			TeamTypeInfo teamTypeInfo = teamTypeInfoService
					.selectTeamTypeInfoById(id);
			if (teamTypeInfo != null) {
				result = responseSuccess(teamTypeInfo);
			} else {
				result = responseFail(ResultCode.MSG_ERROR);
			}
		} else {
			result = responseFail(ResultCode.MSG_PARAMS_NULL);
		}
		return result;
	}
}
